const express = require("express");
const { db } = require("../database");
const { ManagerAuth } = require("../middles");
const { validate, validators } = require("../validate");
const { query, findOne } = require("../logic");

const router = express.Router();
router.use(ManagerAuth);

// routes
router.get(
  "/",
  validate([validators.limit, validators.offset]),
  async (req, res) => {
    res.send({
      success: true,
      query: await query(req, "stock a join product b on a.product_id = b.id", {
        fields: "a.*, json_array(b.id, b.name) product",
      }),
    });
  }
);
const registerRouter = (app) => app.use("/stock", router);
module.exports = { registerRouter };
